/*
	jGrouse framework
	Copyright 2007 by Denis Riabtchik 
	All rights reserved.
	
	Licensed under modified BSD license. See license.txt for details
*/

if (typeof jgrouse == 'undefined')
{
	jgrouse = {};
}


/**
	Utilities for unit testing
	@namespace jgrouse.jsunit
*/


jgrouse.jsunit = 
{
	/**
		Check if condition is true and throw exception if it is not
		@function assert
		@param expr - expression to check
		@param msg - diagnostic message that is included into exception
		@throws jgrouse.jsunit.AssertionException is thrown when assertion fails
	*/
	assert : function(expr, msg)
	{
		if (!expr)
		{
			throw new jgrouse.jsunit.AssertionException(msg);
		}
	},
	
	assertEqual : function(first, second, msg)
	{
		jgrouse.jsunit.assert(first === second, msg? msg : 'Assertion failure - expected ' + first + ' to be equal to ' + second);
	},

	assertNotEqual : function(first, second, msg)
	{
		jgrouse.jsunit.assert(first !== second, msg);
	},

	
	assertTrue : function(expr, msg)
	{
		jgrouse.jsunit.assert(expr === true, msg);
	},

	assertFalse : function(expr, msg)
	{
		jgrouse.jsunit.assert(expr === false, msg);
	},
	
	assertDefined : function(expr, msg)
	{
		jgrouse.jsunit.assert(expr != undefined, msg);
	},
	
	assertUndefined : function(expr, msg)
	{
		jgrouse.jsunit.assert(expr == undefined, msg);
	}
	

	
}

/**
	Exception that is thrown for failed unit tests
	@class jgrouse.jsunit.AssertionException
*/
/**
	@constructor AssertionException
	@param {string} msg - diagnostic message
*/
jgrouse.jsunit.AssertionException = function(msg)
{
	this.msg = msg? msg : 'Assertion failed'
}

jgrouse.jsunit.AssertionException.prototype = 
{
	/**
		Returns string representation of exception
		@function toString
	*/
	toString : function()
	{
		return this.msg;
	}
}
